package cn.lanqiao.rabc.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.http.ResponseEntity;

import java.io.Serializable;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;


    //系统错误
    public static ResponseEntity error(Integer code, String message) {
        return ResponseEntity.status(code).body(message);
    }

    //操作成功，返回数据
    public static ResponseEntity success(Object data) {
        return ResponseEntity.status(200).body(data);
    }

    //操作成功，无返回数据
    public static ResponseEntity success() {
        return ResponseEntity.status(200).build();
    }

    //操作失败，无返回数据
    public static ResponseEntity fail(Integer code, String message) {
        return ResponseEntity.status(code).body(message);
    }
}
